package initialize

import (
	"database/sql"
	"os"
	"server/global"

	_ "github.com/bmizerany/pq"
)

func Postgres() {
	admin := global.GVA_CONFIG.Postgres
	if db, err := sql.Open("postgres", "postgres://"+admin.Username+":"+admin.Password+"@"+admin.Path+"/"+admin.Dbname+"?"+admin.Config); err != nil {
		global.GVA_LOG.Error("Postgresql 启动异常", err)
		os.Exit(0)
	} else {
		global.GVA_DB = db
		global.GVA_DB.SetMaxIdleConns(admin.MaxIdleConns)
		global.GVA_DB.SetMaxOpenConns(admin.MaxOpenConns)
	}
}
